package com.common.groovy


import cn.hutool.json.JSONUtil
import com.common.groovy.adapter.GroovyModelAdapter
import org.springframework.util.ObjectUtils

class GroovyModel{

    private String modelName;
    private GroovyModelAdapter groovyModelAdapter;

    GroovyModel(String modelName, GroovyModelAdapter groovyModelAdapter) {
        this.modelName = modelName
        this.groovyModelAdapter = groovyModelAdapter
    }

    @Override
    Object invokeMethod(String name, Object args) {

        if (ObjectUtils.isEmpty(args)){
            return groovyModelAdapter.call(modelName,name,JSONUtil.createObj())
        }

        return groovyModelAdapter.call(modelName, name, JSONUtil.parse(args[0]))
    }
}

